package com.dnjn.happiness.biz.controller.admin;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dnjn.happiness.biz.controller.common.CommonCheckupController;
import com.dnjn.happiness.biz.domain.Checkup;
import com.dnjn.happiness.biz.domain.vo.CheckupVO;
import com.dnjn.happiness.common.core.utils.bean.BeanUtils;
import com.dnjn.happiness.common.core.utils.poi.ExcelUtil;
import com.dnjn.happiness.common.core.web.domain.AjaxResult;
import com.dnjn.happiness.common.log.annotation.Log;
import com.dnjn.happiness.common.log.enums.BusinessType;
import com.dnjn.happiness.common.security.annotation.RequiresPermissions;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 体检Controller
 *
 * @author happiness
 * @date 2024-03-27
 */
@Tag(name = "biz admin checkup 体检" , description = "体检" )
@RestController
@RequestMapping("/admin/checkup" )
public class AdminCheckupController extends CommonCheckupController {

    /**
     * 导出体检列表
     */
    @Log(title = "体检" , businessType = BusinessType.EXPORT)
    @RequiresPermissions("@ss.hasPermi('biz:checkup:export')" )
    @PostMapping("/export" )
    public void export(HttpServletResponse response, CheckupVO vo) {
        Checkup checkup = new Checkup();
        BeanUtils.copyPropsIgnoreNull(vo, checkup);

        List<Checkup> list = checkupService.list(Wrappers.query(checkup));
        ExcelUtil<Checkup> util = new ExcelUtil<Checkup>(Checkup.class);
        util.exportExcel(response, list, "体检数据" );
    }


    @Log(title = "导入体检" , businessType = BusinessType.IMPORT)
    @RequiresPermissions("@ss.hasPermi('system:user:import')" )
    @PostMapping("/importData" )
    public AjaxResult importData(@RequestBody List<Checkup> list) {
        String message = checkupService.importData(list);
        return AjaxResult.success(message);
    }

    @PostMapping("/importTemplate" )
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<CheckupVO> util = new ExcelUtil<CheckupVO>(CheckupVO.class);
        util.importTemplateExcel(response, "体检数据" );
    }


}
